package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.payment.entity.dos.PaymentLog;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
public class PaymentLogSearchParams extends PageVO {
    @ApiModelProperty(value = "订单编号")
    private String orderSn;

    @ApiModelProperty(value = "支付方式")
    private String paymentMethod;

    @ApiModelProperty(value = "付款客户端")
    private String paymentClient;

    @ApiModelProperty(value = "支付状态")
    private Boolean isPay;

    @ApiModelProperty(value = "合单支付")
    private Boolean isCombine;

    @ApiModelProperty(value = "支付发起开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private String startDate;

    @ApiModelProperty(value = "支付发起结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private String endDate;


    public LambdaQueryWrapper<PaymentLog> generateWrapper() {
        LambdaQueryWrapper<PaymentLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CharSequenceUtil.isNotEmpty(this.orderSn), PaymentLog::getOrderSn, this.orderSn);
        queryWrapper.eq(CharSequenceUtil.isNotEmpty(this.paymentMethod), PaymentLog::getPaymentMethod, this.paymentMethod);
        queryWrapper.eq(CharSequenceUtil.isNotEmpty(this.paymentClient), PaymentLog::getPaymentClient, this.paymentClient);
        queryWrapper.eq(this.isPay != null, PaymentLog::getIsPay, this.isPay);
        queryWrapper.eq(this.isCombine != null, PaymentLog::getIsCombine, this.isCombine);
        queryWrapper.between(this.startDate != null && endDate != null, PaymentLog::getCreateTime, this.startDate, this.endDate);
        return queryWrapper;

    }
}
